<template>
    <view>
        <view class="top">
            <view class="card">
                <image :src="userInfo.avatar" mode="aspectFill" class="avatar"></image>
                <view class="user-info">
                    <view class="username">{{ userInfo.phone }}</view>
                    <view class="user-id">ID: {{ userInfo.id }}</view>
                </view>
            </view>
        </view>
        <view class="menu-container">
            <view class="menu-item" @click="goToAddressPage">
                <view class="icon"><i class="fa-solid fa-location-dot"></i></view>
                <view>我的地址</view>
            </view>
            <view class="menu-item" @click="goToFollowPage">
                <view class="icon"><i class="fa-solid fa-heart"></i></view>
                <view>我的关注</view>
            </view>
            <view class="menu-item" @click="goToOrderPage">
                <view class="icon"><i class="fa-solid fa-shopping-cart"></i></view>
                <view>我的订单</view>
            </view>
        </view>
        <view class="logout-container">
            <button @click="del()" class="logout-button">退出登录</button>
        </view>
    </view>
</template>

<script>
import config from '../config.js';
export default {
    data() {
        return {
            userInfo: {
                avatar: 'https://picsum.photos/100/100',
                phone: '',
                id: ''
            }
        };
    },
    onLoad() {
        // 从本地存储中获取userId
        const userId = uni.getStorageSync('userId');
		const userPhone = uni.getStorageSync('userPhone');
        if (userId) {
            this.userInfo.id = userId;
			this.userInfo.phone = userPhone;
            // 这里可以根据需要从服务器获取更多用户信息来更新userInfo
        }
    },
    methods: {
        del() {
            uni.clearStorageSync();
            uni.navigateTo({
                url: "/pages/login/login"
            });
        },
        goToAddressPage() {
            uni.navigateTo({
                url: "/pages/dingdan/adress"
            });
        },
        goToFollowPage() {
            uni.navigateTo({
                url: "/pages/more/guanzu"
            });
        },
        goToOrderPage() {
            uni.switchTab({
                url: "/pages/dingdan/dingdan"
            });
        }
    }
};
</script>

<style>
.top {
    height: 200px;
    background-color: rgb(47, 166, 235);
    display: flex;
    align-items: center;
    justify-content: center;
}

.card {
    height: 100px;
    width: 80%;
    background-color: #fff;
    display: flex;
    align-items: center;
    justify-content: center; /* 添加水平居中 */
    padding: 10px;
    border-radius: 5px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    margin-right: 15px;
}

.user-info {
    display: flex;
    flex-direction: column;
    align-items: center; /* 添加水平居中 */
}

.username {
    font-size: 18px;
    font-weight: bold;
}

.user-id {
    font-size: 14px;
    color: #666;
}

.menu-container {
    background-color: #fff;
    margin-top: 10px;
}

.menu-item {
    display: flex;
    align-items: center;
    padding: 15px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.menu-item:hover {
    background-color: #f5f5f5;
}

.icon {
    margin-right: 15px;
    font-size: 20px;
    color: rgb(47, 166, 235);
}

.logout-container {
    padding: 15px;
}

.logout-button {
    width: 100%;
    background-color: rgb(47, 166, 235);
    color: #fff;
    padding: 10px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.logout-button:hover {
    background-color: rgb(37, 133, 190);
}
</style>